<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
评论:<input type="text"/>
<ol></ol>
<script>
var input = document.querySelector("input");
var ol = document.querySelector("ol");
input.addEventListener("keyup",function(ev){
if(ev.keyCode === 13){
    if(input.value.length === 0){
        alert("文本框为空，提交失败");
        return;
    }
    var li = document.createElement("li");
    li.innerHTML = input.value+"<button onclick='del(this)'>删除</button>";
    if(ol.childElementCount === 0){
        ol.appendChild(li);
    }else{
ol.insertBefore(li,ol.firstElementChild);
    }
    input.value=null;
}
},false)
function del(ele){
    return confirm("是否删除？")?ele.parentNode.remove() : false;
}
    </script>

</body>
</html>